package com.wanmait.hr.controller;

import com.wanmait.hr.service.ConfigService;
import com.wanmait.hr.service.RegulationsService;
import com.wanmait.hr.service.UserService;
import com.wanmait.hr.util.Pager;
import com.wanmait.hr.vo.Config;
import com.wanmait.hr.vo.Regulations;
import com.wanmait.hr.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**personalCenterController class
 *
 * @author 王志斌
 * @date 2019-02-18
 * */
@Controller
public class personalCenterController {
    @Resource
    private UserService userService;
    @Resource
    private ConfigService configService;
    @Resource
    private RegulationsService regulationsService;

    /**显示登陆员工个人信息
     * @param session
     * @param model
     * */
    @RequestMapping("/manage/personal_center/personal_info")
    public void getList(HttpSession session, Model model)
    {
        //获取登陆用户的id
        //User user = (User)session.getAttribute("userinfo");
        User user = new User();
        user.setId(1);

        //获取用户信息
        User userinfo = userService.getUserInfoById(user);

        //获取config信息
        Config config = configService.configInfoByKey("personal_center/personal_info");
        //获取部门规章制度总条数
        Integer dataCount = regulationsService.dateCountByDepartId(userinfo.getDt().getId());

        model.addAttribute("userinfo", userinfo);
        model.addAttribute("dataCount", dataCount);
        model.addAttribute("config", config);
    }

    @RequestMapping(value = "/manage/personal_center/personal_info", method = RequestMethod.POST)
    public ModelAndView getPostList(HttpSession session, Pager pager)
    {
        //获取登陆用户的id
        //User user = (User)session.getAttribute("userinfo");
        User user = new User();
        user.setId(1);

        //获取用户信息
        User userinfo = userService.getUserInfoById(user);
        //获取部门规章制度总条数
        Integer dataCount = regulationsService.dateCountByDepartId(userinfo.getDt().getId());
        pager.setDataCount(dataCount);
        //获取部门规章制度
        List<Regulations> regulations = regulationsService.getRegulationsByDepartment(userinfo.getDt().getId(), pager);

        ModelAndView mv = new ModelAndView();
        mv.addObject("regulations", regulations);
        mv.setViewName("/manage/personal_center/ajaxSuccessRegulationsBydepart");

        return mv;
    }


}
